package com.pactera.base.commons.enums;

/**
 * @author wangrui
 * 异常枚举
 */

public enum BaseResultEnum{
    /**
     * 状态码
     */
    SUCCESS(200, "操作成功"),
    SERVICE_CURRENTLY_UNAVAILABLE(201, "服务不可用"),
    NOT_LOGIN(401, "未登录或token失效"),
    NOT_AUTHORITY(403, "没有操作权限"),
    MISSING_SUPPORTED_METHODS(405, "不支持的请求方式"),
    MISSING_REQUIRED_ARGUMENTS(4001, "缺少必选参数"),
    INVALID_ARGUMENTS(4002, "非法参数"),
    USER_NOT_BINDING(4031, "用户未绑定"),
    SERVICE_ERROR(500, "服务异常"),
    DATA_NOT_FOUND(5001, "未找到对应数据"),
    DATA_SAVE_FAILED(5002, "数据保存失败"),
    DATA_ALREADY_EXISTED(5003, "数据已存在"),
    DATA_IS_WRONG(5004, "数据有误"),
    DATA_NOT_AVAILABLE(5005, "数据不可用"),
    CONFIGURATION_ERROR(5006, "配置错误"),
    INVALID_OPERATION(5007, "无效操作"),
    CALL_LIMITED(5010, "调用次数超限"),
    CALL_EXCEEDS_LIMITED_FREQUENCY(5011, "调用频率超限"),
    INTERFACE_INNER_INVOKE_ERROR(5020, "系统内部接口调用异常"),
    INTERFACE_OUTER_INVOKE_ERROR(5021, "系统外部接口调用异常"),
    ;

    private Integer code;

    private String desc;

    BaseResultEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static BaseResultEnum code(int code) {
        for (BaseResultEnum bt : values()) {
            if (bt.code == code) {
                return bt;
            }
        }
        return null;
    }
}
